package com.example.example_mvp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.textfield.TextInputEditText;

public class LoginMainActivity extends AppCompatActivity implements ILoginContract.ILoginView {
    private ILoginContract.ILoginPresenter mPresenter;
    private TextInputEditText mUserNameEt;
    private TextInputEditText mPasswordEt;
    private Button mSubmitBtn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_main);

        initView();

        mPresenter = new PresenterImpl(this);

        mSubmitBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.login(getText(mUserNameEt),getText(mPasswordEt));
            }
        });
    }
    private String getText(TextInputEditText textInputEditText){
        return String.valueOf(textInputEditText.getText()).trim();
    }

    private void initView() {
        mUserNameEt=findViewById(R.id.userName);
        mPasswordEt=findViewById(R.id.password);
        mSubmitBtn=findViewById(R.id.brn_login);
    }

    @Override
    public void showDialog() {

    }

    @Override
    public void dismissDialog() {

    }

    @Override
    public void showToast(String message) {
        Toast.makeText(this,message,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void navigateToMain() {
        startActivity(new Intent(this,MainActivity.class));
        finish();
    }
}